package cn.zucc.edu.madq.controller;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
	/**
	 * MD5对字符串加密
	 * 
	 * @param str
	 * @return
	 */
	public static String MD5(String str) {
		StringBuffer strBuf = new StringBuffer("");
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.reset();
			md.update(str.getBytes());
			byte[] b = md.digest();
			for (int i = 0; i < b.length; i++) {
				int temp = b[i] & 0xff;
				if (temp < 16)
					strBuf.append("0");
				strBuf.append(Integer.toHexString(temp));
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return strBuf.toString();
	}

	public static void main(String[] argues) {
		System.out.println(MD5Utils.MD5("111111"));
	}
}
